{template 'web/common/common'}
{template 'web/animal/navbar'}
<link rel="stylesheet" type="text/css" href="../addons/{php echo $_GPC['m']}/resource/swal/dist/sweetalert2.min.css" />
<div class="panel panel-success">
    <div class="panel-heading">
        <h3 class="panel-title">
            已认养详情
        </h3>
    </div>
    <div class="panel-body">
        <form id="sign-form" class="form-horizontal" role="form" method="post" action="{url 'site/entry/order',array('m'=>'kundian_farm','op'=>'saveModel','version_id'=>$_GPC['version_id'])}" name="submit" style="padding: 20px 0;">
            <input type="hidden" name="id" value="{$orderData['id']}">
            <table class="table-striped table-bordered table-hover dataTables-example table">
                <thead>
                    <caption>订单信息</caption>
                    <tr>
                        <td>领养人姓名</td>
                        <td>联系电话</td>
                        <td>订单编号</td>
                        <td>订单总价</td>
                        <td>数量</td>
                        <td>支付方式</td>
                        <td>下单时间</td>
                        <td>订单状态</td>
                    </tr>
                    <tr>
                        <td>{$orderData['username']}</td>
                        <td>{$orderData['phone']}</td>
                        <td>{$orderData['order_number']}</td>
                        <td>{$orderData['total_price']}</td>
                        <td>{$orderData['count']}</td>
                        <td>{$orderData['pay_method']}</td>
                        <td>{php echo date('Y-m-d H:i:s',$orderData['create_time'])}</td>
                        <td>{if $orderData['status']==0}
                            未支付
                            {else if $orderData['status']==1}
                            已支付

                            {else}

                            {/if}</td>

                    </tr>
                </thead>
            </table>

            <table class="table-striped table-bordered table-hover dataTables-example table">
                <thead>
                <caption>家畜信息</caption>
                <tr>
                    <td>id</td>
                    <td>家畜名称</td>
                    <td>封面</td>
                    <td>价格</td>
                    <td>规格</td>
                    <td>购买数量</td>
                    <td>状态</td>
                    <td>预计成熟日期</td>
                </tr>
                <tr>
                    <td><?php echo $adoptData['id'];?></td>
                    <td><?php echo $animalData['animal_name'];?></td>
                    <td><img src="<?php echo $animalData['animal_src'];?>" style="width: 70px;height: 70px;" alt=""></td>
                    <td><?php echo $animalData['price'];?></td>
                    <td>
                        <?php foreach($specItem as $val){?>
                             <?php echo $val['name'].":".$val['spec_value']."   "; ?>
                        <?php } ?>
                    </td>
                    <td><?php echo $orderData['count'];?></td>
                    <td>{if $adoptData['status']==0}
                        未支付
                        {else if $adoptData['status']==1}
                        准备中
                        {else if $adoptData['status']==2}
                        喂养中
                        {else if $adoptData['status']==3}
                        已死亡
                        {else if $adoptData['status']==4}
                        已成熟
                        {else if $adoptData['status']==5}
                        已宰杀并寄送
                        {else}
                        已取消
                        {/if}</td>
                    <td>
                        <input type="hidden" name="adopt_id" value="<?php echo $adoptData['id']?>">
                        <!--<input type="date" value="{$adoptData['predict_ripe']}" id="changeTime" name="predict_ripe">-->
                        {php echo _tpl_form_field_date('predict_ripe', $adoptData['predict_ripe'], $withtime = false) }
                    </td>
                </tr>
                </thead>
            </table>

            <div class="form-group">
                <label class="col-sm-2 control-label">认养状态</label>
                <div class="col-sm-10">
                    <select name="status" class="form-control" id="adopt_status">
                        <option value="1" <?php if($adoptData['status']==1){echo 'selected';}?> >准备中</option>
                        <option value="2" <?php if($adoptData['status']==2){echo 'selected';}?> >喂养中</option>
                        <option value="3" <?php if($adoptData['status']==3){echo 'selected';}?> >已死亡</option>
                        <option value="4" <?php if($adoptData['status']==4){echo 'selected';}?> >已成熟</option>
                        <option value="2">重新领养</option>
                        <option value="5" <?php if($adoptData['status']==5){echo 'selected';}?> >宰杀并寄送</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <input type="hidden" name="adopt_id" value="<?php echo $adoptData['id']?>">
                <button class="btn btn-success" id="saveStatus" type="button">保存</button>
            </div>
            </div>


        </form>
    </div>
</div>
<script>
    require(["../addons/{php echo $_GPC['m']}/resource/swal/dist/sweetalert2.min.js"],function(){
        $(function(){
            $("#saveStatus").click(function () {
                var adopt_status=$("#adopt_status").val();
                var adopt_id=$("input[name='adopt_id']").val();
                $.ajax({
                    type:"post",
                    url:"{url 'site/entry/'.$_GPC['do'],array('m'=>$_GPC['m'],'op'=>'saveStatus','version_id'=>$_GPC['version_id'])}",
                    data:{adopt_id:adopt_id,status:adopt_status},
                    dataType:'json',
                    success:function(res){
                        if(res.status==1){
                            swal('操作成功!', '操作成功!', 'success');
                        }else{
                            swal('操作失败!', '操作失败!', 'error');
                        }
                    }
                })
            })
            $("input[name='predict_ripe']").blur(function () {
                var time=$(this).val();
                var adopt_id=$("input[name='adopt_id']").val();
                swal({
                    title: '提示',
                    text: "确认修改预期成熟时间吗?",
                    type: 'warning',
                    showCancelButton: true,
                    confirmButtonColor: '#3085d6',
                    cancelButtonColor: '#d33',
                    confirmButtonText: '确认',
                    cancelButtonText: '取消',
                }).then(function(isConfirm) {
                    console.log(isConfirm);
                    if (isConfirm) {
                        $.ajax({
                            type:"post",
                            url:"{url 'site/entry/'.$_GPC['do'],array('m'=>$_GPC['m'],'op'=>'changeTime','version_id'=>$_GPC['version_id'])}",
                            data:{adopt_id:adopt_id,time:time},
                            dataType:'json',
                            success:function(res){
                                if(res.status==1){
                                    swal('操作成功!', '操作成功!', 'success');
//                                    alert("操作成功")
                                }else{
                                    swal('操作失败!', '操作失败!', 'error');
                                }
                            }
                        })
                    }
                })

            })
        })
    })
</script>

